home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 329_02 / xcxref.c < prev    next >
C/C++ Source or Header  |  1990-06-09  |  51KB  |  1,761 lines

  1.       /***********************************************************
  2.  
  3.       XCXREF  -  A 'C' Concordance Utility
  4.  
  5.       Version 1.0   xc     - January, 1982
  6.       Version 1.0   xcxref - May,     1990
  7.  
  8.       Copyright (c) 1982 by Philip N. Hisley
  9.  
  10.               Philip N. Hisley
  11.               548H Jamestown Court
  12.               Edgewood, Maryland 21040
  13.               (301) 679-4606
  14.  
  15.       Released for non-commercial distribution only
  16.  
  17.       Converted to IBM/PC CI/C86 by David N. Smith, May/June 1983
  18.       with enhancements and Lattice compiler support in December 1983.
  19.  
  20.               David N. Smith
  21.               44 Ole Musket Lane
  22.               Danbury, CT 06810
  23.               (203) 748-5934
  24.               CompuServe: 73145,153
  25.  
  26.       Changes Copyright (c) 1983 by David N. Smith
  27.       Permission granted to copy for non-commercial purposes.
  28.  
  29.       Version v1.0   XCXREF - May, 1990.
  30.       Program functions extended, hence the name change.
  31.  
  32.               Martin D. Winnick
  33.               5301 El Arbol Drive
  34.               Carlsbad, CA 92008
  35.               (619) 431-0485
  36.               CompuServe: 71665,456
  37.               May 1990
  38.  
  39.       Changes Copyright (c) 1990 by Martin D. Winnick
  40.       Permission granted to copy for non-commercial use only.
  41.       See the accompanying xcxref.doc file for program history and
  42.       all change details.
  43.  
  44.  
  45.       Abstract:
  46.  
  47.       'XCXREF' is a cross-reference utility for 'C' programs.
  48.       Its will handle nested #include files and properly process
  49.       nested comments.
  50.  
  51.       Option flags control the following features:
  52.  
  53.       Usage: xcxref <filename> <flag(s)>
  54.  
  55.       Flags: -e            = Write program data to log file
  56.              -g            = Ignore missing files
  57.              -i            = Enable #include processing
  58.              -l            = Generate listing only - no xref
  59.              -o <outfile>  = Write output to named file
  60.              -p            = Write output to line printer LPT1
  61.              -r            = Cross-reference 'C' reserved words
  62.              -s            = Write output to video screen
  63.              -w width      = Width of output page; default = 78
  64.                                                    max     = 150
  65.       Flags MUST FOLLOW all input file names
  66.  
  67.       ***********************************************************/
  68.  
  69. #include "bios.h"
  70. #include "ctype.h"
  71. #include "direct.h"
  72. #include "dos.h"
  73. #include "stdio.h"
  74. #include "stdlib.h"
  75. #include "string.h"
  76. #include "time.h"
  77.  
  78. #ifndef  TRUE
  79. #define  TRUE        1
  80. #define  FALSE       0
  81. #endif
  82.  
  83. #define  ERROR      -1
  84. #define  FF         0x0C        /* formfeed                            */
  85. #define  FOREVER    for(;;)
  86. #define  LINES_PER_PAGE 60
  87. #define  LPT1       0           /* defines LPT1                        */
  88. #define  MAX_ALPHA  53          /* maximum alpha chain heads           */
  89. #define  MAX_LEN    31          /* maximum identifier length           */
  90. #define  MAX_REF     5          /* maximum refs per ref-block          */
  91. #define  MAX_REFS_LINE  10      /* maximum refs per line               */
  92. #define  MAX_WRD  5000          /* maximum number of identifiers (749) */
  93. #define  MAXCOL     78          /* right margin for listing line       */
  94. #define  MAXLINE   150          /* maximum print line length.          */
  95. #define  MINCOL     30          /* minimum value for -w option         */
  96.  
  97. struct alpha_hdr
  98.     {
  99.     struct id_blk *alpha_top;
  100.     struct id_blk *alpha_lst;
  101.     };
  102.  
  103. struct  id_blk
  104.     {
  105.     char  id_name[MAX_LEN];
  106.     struct id_blk *alpha_lnk;
  107.     struct rf_blk *top_lnk;
  108.     struct rf_blk *lst_lnk;
  109.     };
  110.  
  111. struct  rf_blk
  112.     {
  113.     int  ref_item[MAX_REF];
  114.     int  ref_cnt;
  115.     struct rf_blk *next_rfb;
  116.     };
  117.  
  118. struct alpha_hdr alpha_vector[MAX_ALPHA];
  119. struct dosdate_t dt;
  120. struct id_blk *id_vector[MAX_WRD];
  121.  
  122. int     al_count   = 0;       /* number of alpha links        */
  123. int     edtnum     = 0;       /* edit line number             */
  124. int     file_level = 0;       /* file level                   */
  125. int     hash_hits  = 0;       /* number of conflict hits      */
  126. int     id_cnt     = 0;       /* number of unique identifiers */
  127. int     id_count   = 0;       /* number of id structs alloc.  */
  128. int     linum      = 0;       /* line number                  */
  129. int     paglin     = 0;       /* page line counter            */
  130. int     pagno      = 0;       /* page number                  */
  131. int     rf_count   = 0;       /* number of rf structs alloc.  */
  132.  
  133. short   base_row    = 0;             /* basic data display video row   */
  134. short   maxcol      = MAXCOL;        /* right column for listing       */
  135. short   maxrefs     = MAX_REFS_LINE; /* max references per line        */
  136. short   vline       = 10;            /* work data display video column */
  137.  
  138. short   do_echo     = TRUE;
  139. short   do_includes = FALSE;
  140. short   do_lprint   = FALSE;
  141. short   do_numbrs   = TRUE;
  142. short   do_outfile  = FALSE;
  143. short   do_res_wds  = FALSE;
  144. short   do_screen   = FALSE;
  145. short   file_queue  = FALSE;
  146. short   ignore      = FALSE;
  147. short   infl_open   = FALSE;
  148. short   lf_open     = FALSE;
  149. short   list_only   = FALSE;
  150. short   log_on      = FALSE;
  151. short   prt_ref     = FALSE;
  152. short   qfl_open    = FALSE;
  153. short   qfirst      = TRUE;
  154.  
  155. char    current_file[_MAX_PATH] = { '\0' };
  156. char    glbl_file[_MAX_PATH]    = { '\0' };
  157. char    list_file[_MAX_PATH]    = { '\0' };
  158. char    log_file[]              = { "XCXREF.LOG" };
  159. char    work_name[_MAX_PATH]    = { '\0' };
  160.  
  161. /* Working file name components */
  162. char    wdrive[_MAX_DRIVE]      = { '\0' };
  163. char    wdir[_MAX_DIR]          = { '\0' };
  164. char    wfname[_MAX_FNAME]      = { '\0' };
  165. char    wext[_MAX_EXT]          = { '\0' };
  166.  
  167. /* Current default directory components */
  168. char    ddrive[_MAX_DRIVE]      = { '\0' };
  169. char    ddir[_MAX_DIR]          = { '\0' };
  170.  
  171. /* Alternate path name components */
  172. char    adrive1[_MAX_DRIVE]     = { '\0' };
  173. char    adir1[_MAX_DIR]         = { '\0' };
  174. char    adrive2[_MAX_DRIVE]     = { '\0' };
  175. char    adir2[_MAX_DIR]         = { '\0' };
  176. char    adrive3[_MAX_DRIVE]     = { '\0' };
  177. char    adir3[_MAX_DIR]         = { '\0' };
  178. char    adrive4[_MAX_DRIVE]     = { '\0' };
  179. char    adir4[_MAX_DIR]         = { '\0' };
  180. char    xfname[_MAX_FNAME]      = { '\0' };
  181. char    xext[_MAX_EXT]          = { '\0' };
  182.  
  183. char    b22[]         = { "                      " };
  184. char    *days[]       = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  185. char    emsgs[71]     = { '\0' };
  186. char    pdate[]       = { "Thu 05/10/90" };
  187. char    prt_line[256] = { '\0' };
  188. char    version[]     = { "v1.0" };
  189. char    xcx_name[]    = { "XCXREF ... " };
  190. char    xname[]       = { "XCXREF.LST" };
  191.  
  192. FILE    *f_list_file;         /* list  file            */
  193. FILE    *lgfile;              /* program data log file */
  194. FILE    *ofile;               /* general open file     */
  195.  
  196. /* function prototypes */
  197. struct rf_blk *add_rf(struct rf_blk *adr_ptr, int adr_ref);
  198. struct id_blk *alloc_id(char *aid_token);
  199. struct rf_blk *alloc_rf(int arf_ref);
  200. void chain_alpha(struct id_blk *ca_ptr, char *ca_token);
  201. int  check_for_resword(char *c_token);
  202. void clr_scrn(short crow, short nrows);
  203. void do_prints(int pparm);
  204. void do_print_xrefs(void);
  205. void echo(char c);
  206. void echochar(char c);
  207. int  get_file_char(FILE *cfile, int *f_eof);
  208. int  get_fqueue(char *qfn);
  209. void get_include_fileid(char *token, FILE *ifile, short parm);
  210. int  get_token(FILE *gfile, char *g_token, int *g_toklen, int *g_eoflg, char x_chr);
  211. void list_err(int parm);
  212. void logit(short parm);
  213. void lprintr(char *buffer);
  214. void new_line(void);
  215. int  openlist(char *lname);
  216. FILE *open_rfile(void);
  217. void pause(clock_t mcount);
  218. void pexit(int xparm);
  219. void print_header(void);
  220. int  proc_file(int incnum);
  221. void put_token(char *p_token, int p_ref);
  222. char read_file_char(FILE *rfile, int *r_eoflg, char rd_flg);
  223. void set_csr(short vrow, short vcol);
  224. void use_err(void);
  225.  
  226. /*************************************************************************/
  227.  
  228. int main(int p_argc, char **p_argv)
  229. {
  230.     char *arg, **arg